package com.nc.servlet;

import com.nc.bean.Person;
import com.nc.dao.PersonDao;
import com.nc.dao.impl.PersonDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/queryAll")
public class QueryAllServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String name = request.getParameter("name");
        String checkbox = request.getParameter("checkbox");
        PersonDao personDao = new PersonDaoImpl();
        List<Person> list = null;
        if (checkbox!=null){
            if (checkbox.equals("-1")){
                checkbox = null;
            }
        }
        list = personDao.queryBySex(checkbox,name==null?"":name);

        request.setAttribute("list",list);
        request.getRequestDispatcher("index.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
